#include <stdio.h>
#include "festival_8.h"

// 公历节日结构体
typedef struct {
    int month;
    int day;
    const char *name;
} SolarFestival;

// 农历节日结构体
typedef struct {
    int lunar_month;
    int lunar_day;
    const char *name;
} LunarFestival;

// 公历节日数据
static const SolarFestival solarFestivals[] = {
    {1, 1, "元旦"},
    {2, 14, "情人节"},
    {3, 8, "妇女节"},
    {4, 1, "愚人节"},
    {5, 1, "劳动节"},
    {6, 1, "儿童节"},
    {10, 1, "国庆节"},
    {12, 25, "圣诞节"},
    // 可以补充更多公历节日
};

// 农历节日数据
static const LunarFestival lunarFestivals[] = {
    {1, 1, "春节"},
    {1, 15, "元宵节"},
    {5, 5, "端午节"},
    {7, 7, "七夕节"},
    {8, 15, "中秋节"},
    {9, 9, "重阳节"},
    {12, 8, "腊八节"},
    {12, 23, "小年"},
    // 可以补充更多农历节日
};

// 打印指定月份的公历节日
static void printSolarFestivalsByMonth(int month) {
    int found = 0;
    printf("公历 %d 月的节日有：\n", month);
    for (int i = 0; i < (int)(sizeof(solarFestivals)/sizeof(solarFestivals[0])); i++) {
        if (solarFestivals[i].month == month) {
            printf("  %d月%d日 : %s\n", solarFestivals[i].month, solarFestivals[i].day, solarFestivals[i].name);
            found = 1;
        }
    }
    if (!found) {
        printf("  该月份无公历节日记录。\n");
    }
}

// 打印所有农历节日
static void printAllLunarFestivals(void) {
    printf("常见农历节日如下：\n");
    for (int i = 0; i < (int)(sizeof(lunarFestivals)/sizeof(lunarFestivals[0])); i++) {
        printf("  农历%d月%d日 : %s\n", lunarFestivals[i].lunar_month, lunarFestivals[i].lunar_day, lunarFestivals[i].name);
    }
}

// 显示节日菜单及处理
void showFestivals(void) {
    int choice;
    printf("请选择要显示的节日类型：\n");
    printf("1. 公历节日\n");
    printf("2. 农历节日\n");
    printf("请输入数字选择：");
    if (scanf("%d", &choice) != 1) {
        printf("输入错误\n");
        return;
    }
    if (choice == 1) {
        int month;
        printf("请输入要查询的月份 (1-12): ");
        if (scanf("%d", &month) != 1 || month < 1 || month > 12) {
            printf("无效的月份\n");
            return;
        }
        printSolarFestivalsByMonth(month);
    } else if (choice == 2) {
        printAllLunarFestivals();
    } else {
        printf("无效选择\n");
    }
}
